fix: correctly output packages from osv-scanner.json source in spdx format#2641
Open
Mananshah237 wants to merge 2 commits intogoogle:mainfrom
Open
fix: correctly output packages from osv-scanner.json source in spdx format#2641Mananshah237 wants to merge 2 commits intogoogle:mainfrom
Mananshah237 wants to merge 2 commits intogoogle:mainfrom
Conversation
…format Packages loaded from an osv-scanner.json results file have Inventory == nil because PackageInfo.Inventory is not populated during JSON deserialization. PrintSPDXResults was blindly appending nil Inventory values, causing the SPDX converter to silently skip all such packages. Fix by constructing a synthetic extractor.Package from available PackageInfo fields (name, version, ecosystem) when Inventory is nil. Maven packages require special handling to produce the correct pkg:maven PURL. Fixes google#2192
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2641 +/- ##
===========================================
+ Coverage 68.03% 79.56% +11.53%
===========================================
Files 173 117 -56
Lines 13405 8042 -5363
===========================================
- Hits 9120 6399 -2721
+ Misses 3577 1263 -2314
+ Partials 708 380 -328 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
another-rex
reviewed
Mar 16, 2026
Collaborator
another-rex
left a comment
There was a problem hiding this comment.
Nice, pretty neat fix!
Just need to fix the linting issues and one comment, otherwise LGTM.
|
|
||
| // inventoryFromPackageInfo constructs a synthetic extractor.Package from a PackageInfo | ||
| // for packages that don't have a populated Inventory field (e.g., loaded from osv-scanner.json). | ||
| func inventoryFromPackageInfo(pkg models.PackageInfo) *extractor.Package { |
Collaborator
There was a problem hiding this comment.
Have this function return an error as well, rather than just nil, to be handled in the caller.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2192
Packages loaded from an
osv-scanner.jsonresults file haveInventory == nilbecause
PackageInfo.Inventoryis not populated during JSON deserialization.PrintSPDXResultswas blindly appending nil Inventory values, causing theSPDX converter to silently skip all such packages.
This fix constructs a synthetic
extractor.Packageusing the availablePackageInfo fields (name, version, ecosystem) when Inventory is nil.
Maven packages require special handling because their names are stored as
groupId:artifactIdin osv-scanner. The scalibr PURL converter requiresjavalockfile.MetadatawithGroupIDandArtifactIDto generate the correctpkg:maven/groupId/artifactId@versionPURL.This ensures packages from osv-scanner.json sources appear correctly
in the generated SPDX SBOM output.